<?php
      // 1              成功
      // 2              数据库连接错误;
      // 3              数据库创建失败
      // 4              数据为空或不存在
      // 5              插入数据库错误
      // 6              登录错误
      header("Content-type:text/html;charset=utf-8");

      $db_username = "root";
      $db_password = "root";
      $db_host = "localhost:3306";
      global $tb_list;
      $tb_list = array("dbp","zyy","xyy","ty","zsy","ghx","jcm");

      $con = mysql_connect($db_host,$db_username,$db_password);

      if(!$con){
            $json_arr = array( "status" => "error" , "stateCode" => "2" , "errorType" => "mySQL error".mysql_error());
            die(json_encode($json_arr));
      }
      $db_selected = mysql_select_db("group8",$con);
      if(!$db_selected){
            if(mysql_query("CREATE DATABASE group8",$con)){
                  mysql_select_db("group8",$con);
                  $json_arr = array( "status" => "success" , "stateCode" => "1", "type"=> "grounp8创建成功");
                  die(json_encode($json_arr));
            }
            else{
                  $json_arr = array( "status" => "error" , "stateCode" => "3", "type"=> "grounp8创建失败");
                  die(json_encode($json_arr));
            }
      }
      // 创建表
      function createTable($server,$author){
            // 找到所有表，看看表是否存在
            $show_SQL = "SHOW TABLES";
            $show_res = mysql_query($show_SQL,$server);
            if(!$show_res){
                  $json_arr = array( "status" => "error" , "stateCode" => "4" , "errorType" => "There are no tables in the database");
                  die(json_encode($json_arr));
            }
            $isExist = false;
            while($row = mysql_fetch_array($show_res)){
                  if($row[0] === $author){ 
                        $isExist = true;
                  } 
            }
            // 创建表
            if(!$isExist){
                  $tb_SQL = "CREATE TABLE $author (
                        `username`  varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,
                        `password`  varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,
                        `email`  varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,
                        `id`  int(4) NOT NULL AUTO_INCREMENT ,
                        PRIMARY KEY (`id`)
                  )";
                  mysql_query($tb_SQL,$server);
            }
      }
?>